package com.ruoyi.loan.product.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.TbLoanProductsIdVo;
import com.ruoyi.common.core.domain.TbLoanProductsVo;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.loan.product.domain.TbLoanProducts;
import com.ruoyi.loan.product.service.TbLoanProductsService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 张树智
 * @version 1.0
 * @description: ProductController
 * @date 2023-01-13 10:55
 */
@RestController
@RequestMapping("/product")
@ApiOperation("产品中心模块")
@Slf4j
public class ProductController extends BaseController {

    @Resource
    TbLoanProductsService tbLoanProductsService;

    /**
     * 贷款产品添加
     * @param products
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("贷款产品添加")
    public R add(@RequestBody TbLoanProducts products){
        return tbLoanProductsService.add(products);
    }

    /**
     * 贷款产品修改
     * @param products
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("贷款产品修改")
    public R update(@RequestBody TbLoanProducts products){
        return tbLoanProductsService.updateByProduct(products);
    }

    /**
     * 贷款产品删除
     * @param productsIdVo
     * @return
     */
    @PostMapping("/delete")
    @ApiOperation("贷款产品删除")
    public R update(@RequestBody TbLoanProductsIdVo productsIdVo){
        return tbLoanProductsService.deleteById(productsIdVo);
    }

    /**
     * 产品列表
     * @param productsVo
     * @return
     */
    @PostMapping("/findPage")
    @ApiOperation("贷款产品分页")
    public TableDataInfo findAll(@RequestBody TbLoanProductsVo productsVo){
        startPage();
        //查询数据
        List<TbLoanProductsVo> list=tbLoanProductsService.findAll(productsVo);
        return getDataTable(list);
    }
}
